package cn.liontalk.controller;

import cn.liontalk.service.UserService;
import cn.liontalk.vo.LoginVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import cn.liontalk.common.result.Result;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * @author: 周哲
 * @package: cn.liontalk.controller
 * @description:
 * @date: 2019/1/19 15:07
 * @version: V1.0
 */
@Controller
public class LoginController {

    @Autowired
    private UserService userService;


    private static Logger log = LoggerFactory.getLogger(LoginController.class);

    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public String loginPage() {
        return "login";
    }


    @RequestMapping(value = "/login", method = RequestMethod.POST)
    @ResponseBody
    public Result <String> doLogin(HttpServletResponse response,@Valid LoginVO loginVO) {
        log.info("User Login ...");
        String result = userService.login(response,loginVO);
        return Result.success(result);
    }
}
